/*
* INSANE - Interactive Structural Analysis Environment
*
* Copyright (C) 2003-2005
* Universidade Federal de Minas Gerais
* Escola de Engenharia
* Departamento de Engenharia de Estruturas
* 
* Author's email :    insane@dees.ufmg.br
* Author's website :  http://www.dees.ufmg.br/insane
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
package br.ufmg.dees.insane.model.disc.node;

import br.ufmg.dees.insane.model.disc.pointforce.PointForce;
import br.ufmg.dees.insane.util.IPoint3d;
import br.ufmg.dees.insane.util.IVector;


/**
*A class representing a node.
*
*@author Fonseca, Flavio & Pitangueira, Roque
*@version 1.0
*@since September 2003
*/

public class Node implements java.io.Serializable {
	
	private static final long serialVersionUID = 1L;

	/** The label of this Node. */
	protected String label;
	
	/** The coords of this Node. */
	protected IPoint3d coord = new IPoint3d();
	
	/** The six possible displacements of this Node.<br>
	*They are stored in this order: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected IVector displacement = new IVector(6);
	
	/** The six possible displacements of this Node.<br>
	*They are stored in this order: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected String[] displacementName = new String[6];
	
	/** The six possible forces on this Node.<br>
	*They are stored in this order: <i>Fx, Fy, Fz, Mx, My, Mz</i><p>
	* <i><b>It must be informed in this node's local axis.</b></i>*/
	protected IVector force = new IVector(6);
	
	/** The six possible restraints of this Node.<p>
	*<i>true</i> = There is a restriction.<br>
	*<i>false</i> = There is no restriction.<p>
	*The restrictions in each position are related to these displacements: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected boolean[] restraints = new boolean[6];
	
	/** The number of the equations of this Node.<br>
	* They are related to these displacements: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected int[] equations = new int[6];
	
	/** The stiffness constants of this Node, supposing it's an elastic support.
	* They are related to these displacements: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected double[] mySpring = new double[6];
	
	/** The prescribed displacements of this Node.
	* They are stored in this order: <i>Dx, Dy, Dz, Rx, Ry, Rz</i>*/
	protected IVector preDisplacement = new IVector(6);
	
	/** The angle between the local X axis and the global X axis.<p>
	* It is positive in the counter-clockwise way.*/
	protected double angle;
	
	/** The six possible reactions forces on this Node.<br>
	*They are stored in this order: <i>Fx, Fy, Fz, Mx, My, Mz</i><p>
	* <i><b>It is informed in this node's local axis.</b></i>*/
	protected IVector reactions = new IVector (6);
	
	protected PointForce pf = new PointForce();
	
	public PointForce getPointForce(){
		return (pf);
	};
	
	
	public void setPointForce(PointForce p){
		pf = p;
	};
	
//********************************************************************************
	
	/** Returns the label of this Node.
	*@return The label of this Node.
	*/
	public String getLabel(){
		return (label);
	};
	
	/** Sets the label of this Node.
	*@param a The label of this Node.
	*/
	public void setLabel(String a){
		label = a;
	};
	
//********************************************************************************
	
	/** Returns the coord of this Node.
	*@return The coord of this Node..
	*/
	public IPoint3d getCoord() {
		return (coord);
	};
	
	/** Sets the coord of this Node.
	*@param a The coord of this Node.
	*/
	public void setCoord(IPoint3d a) {
		coord = a;
	};
	
	/** Sets the coord of this Node.
	*@param x The coord X of this Node.
	*@param y The coord Y of this Node.
	*@param z The coord Z of this Node.
	*/
	public void setCoord(double x, double y, double z) {
		IPoint3d aux = new IPoint3d(x, y, z);
		coord = aux;
	};
	
	/** Sets the coord of this Node.
	*@param x The coord X of this Node.
	*@param y The coord Y of this Node.
	* The coord Z is set to zero.
	*/
	public void setCoord(double x, double y) {
		IPoint3d aux = new IPoint3d(x, y, 0);
		coord = aux;
	};
	
//********************************************************************************
	
	/** Returns the restraint of this Node at the specified position.
	*@param a The position of the restraint.
	*@return The restraint at the specified position.
	*/
	public boolean getRestraint(int a){
		return (restraints[a]);
	};
	
	/** Sets the restraint of this Node at the specified position.
	*@param a The position of the restraint.
	*@param b The restraint at the specified position.
	*/
	public void setRestraint(int a, boolean b){
		restraints[a] = b;
	};
	
//********************************************************************************
	
	/** Returns the number of the equation related to this displacement of this Node.
	*@param a The position of the displacement to which the equation is related.
	*@return The number of the equation related to this displacement.
	*/
	public int getEquation(int a){
		return (equations[a]);
	};
	
	/** Sets the number of the equation related to this displacement of this Node.
	*@param a The position of the displacement to which the equation is related.
	*@param b The number of the equation related to this displacement.
	*/
	public void setEquation(int a, int b){
		equations[a] = b;
	};
	
//********************************************************************************
	
	/** Returns the displacement of this Node at the specified position.
	*@param a The position of the displacement.
	*@return The displacement at the specified position.
	*/
	public double getDisplacement(int a){
		return (displacement.getElement(a));
	};
	
	/** Sets the displacement of this Node at the specified position.
	*@param a The position of the displacement.
	*@param b The displacement at the specified position.
	*/
	public void setDisplacement(int a, double b){
		displacement.setElement(a, b);
	};
	
//********************************************************************************
	
	/** Returns the force on this Node at the specified position.
	*@param a The position of the force.
	*@return The force at the specified position.
	*/
	public double getForce(int a){
		return (force.getElement(a));
	};
	
	/** Sets the force on this Node at the specified position.
	*@param a The position of the force.
	*@param b The force at the specified position.
	*/
	public void setForce(int a, double b){
		force.setElement(a, b);
	};
	
//********************************************************************************
	
	/** Returns the stiffness of this Node at the specified position.
	*@param a The position of the stiffness.
	*@return The stiffness at the specified position.
	*/
	public double getSpring(int a)
	{
		return (mySpring[a]);
	};
	
	/** Sets the stiffness of this Node at the specified position.
	*@param a The position of the stiffness.
	*@param b The stiffness at the specified position.
	*/
	public void setSpring(int a, double b)
	{
		mySpring[a] = b;
	};
	
//********************************************************************************
	
	/** Returns the prescribed displacement of this Node at the specified position.
	*@param a The position of the prescribed displacement.
	*@return The prescribed displacement at the specified position.
	*/
	public double getPreDisplacement(int a)
	{
		return (preDisplacement.getElement(a));
	};
	
	/** Sets the prescribed displacement of this Node at the specified position.
	*@param a The position of the prescribed displacement.
	*@param b The prescribed displacement at the specified position.
	*/
	public void setPreDisplacement(int a, double b)
	{
		preDisplacement.setElement(a, b);
	};
	
//********************************************************************************
	
	/** Returns this Node's angle.
	* @return This Node's angle.
	*/
	public double getAngle()
	{
		return (angle);
	};
	
	/** Sets this Node's angle.
	* @param a This Node's angle.
	*/
	public void setAngle(double a)
	{
		angle = a;
	};
	
//********************************************************************************

	/** Returns the reaction force on this Node at the specified position.
	*@param a The position of the reaction force.
	*@return The reaction force at the specified position.
	*/
	public double getReaction(int a)
	{
		return (reactions.getElement(a));
	};
	
	/** Sets the reaction force on this Node at the specified position.
	*@param a The position of the reaction force.
	*@param b The reaction force at the specified position.
	*/
	public void setReaction(int a, double b)
	{
		reactions.setElement(a, b);
	};
	
	public String getDisplacementsName(int i)
	{
		return displacementName[i];
		
	};
	
	public void setDisplacementsName()
	{
		displacementName[0]= "Dx";
		displacementName[1]= "Dy";
		displacementName[2]= "Dz";
		displacementName[3]= "Rx";
		displacementName[4]= "Ry";
		displacementName[5]= "Rz";
	};
//********************************************************************************
	
	/** Sets to zero all the results calculated. */
	public void cleanResults() {
		
		displacement.zero();
		reactions.zero();
		
	}
	
//********************************************************************************
}
